package com.example.a10928.weifriend.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.a10928.weifriend.R;

public class ItemLayout extends RelativeLayout {


    TextView tv_title;

    public ItemLayout(Context context) {
        super(context);
    }

    public ItemLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.layout_item, this);
        ImageView iv = (ImageView) findViewById(R.id.iv_icon);
        tv_title = (TextView) findViewById(R.id.tv_title);


        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ItemLayout);
        int drawable = typedArray.getResourceId(R.styleable.ItemLayout_ItemLayout_iv,R.drawable.home_page);
        String title = typedArray.getString(R.styleable.ItemLayout_ItemLayout_tv);
        if(title==null){
            title="";
        }

        typedArray.recycle();//释放资源

        iv.setImageResource(drawable);
        tv_title.setText(title);



    }



}
